package com.wefans.wefansapp.activity;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wefans.wefansapp.R;
import com.wefans.wefansapp.common.tool.data.ResMyPointCouponItemData;
import com.wefans.wefansapp.common.tool.data.ResMyPointStarItemData;

public class MyPointAdapter extends BaseAdapter {

	private ArrayList<Object> mPointList= null;
    private LayoutInflater mInflater = null;
    private ViewHolder viewHolder = null;

	public MyPointAdapter(Context c, ArrayList<Object> pointList) {
		super();
		this.mInflater = LayoutInflater.from(c);
		this.mPointList = pointList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mPointList.size();
	}


	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mPointList.get(position);
	}


	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        
        if(v == null){
            viewHolder = new ViewHolder();
            v = mInflater.inflate(R.layout.list_item_mypoint, null);
            viewHolder.tv_Name = (TextView) v.findViewById(R.id.TV_MYPOINT_TITLE);
            viewHolder.tv_Desc = (TextView) v.findViewById(R.id.TV_MYPOINT_DESC);
            viewHolder.tv_Count = (TextView) v.findViewById(R.id.TV_MYPOINT_COUNT);
            viewHolder.tv_Unit = (TextView) v.findViewById(R.id.TV_MYPOINT_UNIT);
            viewHolder.iv_Unit = (ImageView) v.findViewById(R.id.IV_MYPOINT_UNIT);
            v.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)v.getTag();
        }
        
        if (getItem(position) != null) {
        	if (getItem(position) instanceof ResMyPointCouponItemData) {
            	ResMyPointCouponItemData dtPoint = (ResMyPointCouponItemData) getItem(position);
            	viewHolder.tv_Name.setText(dtPoint.getStack_name());
            	viewHolder.tv_Desc.setText(dtPoint.getStack_date());
            	viewHolder.tv_Count.setText(dtPoint.getStack_num());
            	viewHolder.tv_Unit.setVisibility(View.VISIBLE);
            	viewHolder.iv_Unit.setVisibility(View.GONE);
            	
            } else if (getItem(position) instanceof ResMyPointStarItemData) {
            	ResMyPointStarItemData dtPoint = (ResMyPointStarItemData) getItem(position);
            	viewHolder.tv_Name.setText(dtPoint.getStack_name());
            	viewHolder.tv_Desc.setText(dtPoint.getStack_date());
            	viewHolder.tv_Count.setText(dtPoint.getStack_star());
            	viewHolder.tv_Unit.setVisibility(View.GONE);
            	viewHolder.iv_Unit.setVisibility(View.VISIBLE);
            }
        }
         
        return v;
	}

	class ViewHolder {        
        public TextView tv_Name;
        public TextView tv_Desc;
        public TextView tv_Count;
        public TextView tv_Unit;
        public ImageView iv_Unit;
    }
}
